<!--
* description: 良品不良品转换 备件信息弹出框（含输入框）
-->
<template>
  <section class="carTypeConfig">
    <el-col :span="span">
      <lableName
        :style="span == 12 ? 'width:14%' : ''"
        :validrule="validrule"
        :curLabelName="curLabelName"
        :isShowLabel="isShowLabel"
        :isRequire="isRequire"
      ></lableName>
      <el-input
        :style="setInputWidth(span)"
        placeholder="请选择"
        v-model="modelText"
        :disabled="disabled"
        size="small"
        suffix-icon="el-icon-menu"
        @clear="clearCode"
        clearable
        @focus="getFocusCode"
        :readonly="readonly"
      ></el-input>
      <validateFormate :curLabelName="curLabelName" :validrule="validrule"></validateFormate>
    </el-col>
    <PartInfo
      :popupsVisible="curPopupsVisible"
      :codeField="codeField"
      :textField="textField"
      :comType="comType"
      :valueObject="curValueObject"
      :popupsKey="popupsKey"
      :code="modelCode"
      :text="modelText"
      :key="curPopupsKey"
      :isMul="isMul"
      :returnCodeField="returnCodeField"
      :returnTextField="returnTextField"
      @changeCode="getComponentCode1"
      ref="dialogComponent"
      :WAREHOUSE_ID="WAREHOUSE_ID"
    ></PartInfo>
  </section>
</template>
<script>
import { searchInputMixins } from "@/components/mixins/searchInputMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
// import lableName from "@/components/lableName";
import PartInfo from "@/components/wms/wmsEjectWindows/wmsPartInfoStorage/edit";
// import validateFormate from "@/components/validateFormate";
export default {
  // 组件混入对象
  mixins: [searchInputMixins, valueObjectMixins],
  components: {
    PartInfo,
    lableName: () => import("@/components/lableName"), //标题溢出样式组件
    validateFormate: () => import("@/components/validateFormate") //校验提示样式组件
  },
  props: {
    WAREHOUSE_ID: { type: String, default: "" }
  },
  data() {
    return {
      curLabelName: this.labelName === "" ? "备件编码" : this.labelName,
      row: {}
    };
  },
  methods: {
    getFocusCode(e) {
      if (
        this.$refs[this.inputRef] &&
        this.$refs[this.inputRef].focused !== true
      ) {
        return;
      }
      // disabled不能为true
      if (!this.curPopupsVisible && this.disabled !== true) {
        e.target.blur();
        if (!this.WAREHOUSE_ID) {
          this.$message({
            message: "请先选择仓库名称"
          });
          return;
        }
        // 判断必须查询条件字段
        if (
          this.mustFields &&
          this.mustFields !== null &&
          this.curValueObject
        ) {
          const arrFields = this.mustFields.split("|");
          for (var i in arrFields) {
            if (
              !this.curValueObject[arrFields[i]] ||
              this.curValueObject[arrFields[i]] === ""
            ) {
              this.onHasNoMust(this.mustFields, this.curValueObject);
              return;
            }
          }
        }
        this.curPopupsVisible = true;
        this.curPopupsKey = this.codeField + this.$utils.generateId();
      }
    },
    getComponentCode1(
      code,
      text,
      codeField,
      comType,
      popupsKey,
      textField,
      otherField,
      selectData
    ) {
      this.curPopupsVisible = false;
      this.curPopupsKey = codeField + this.$utils.generateId();
      if (!code) {
        return;
      }
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      let results = selectData[0];
      this.row = selectData[0];
      for (let key in parent.formField) {
        if (results.hasOwnProperty(key)) {
          parent.formField[key] = results[key];
        }
      }
      this.$emit(
        "changeCode",
        code,
        text,
        codeField,
        comType,
        popupsKey,
        textField,
        otherField,
        selectData
      );
    },
    setInputWidth(span) {
      switch (span) {
        case 6:
          return "";
        case 12:
          return "width:85%;line-height: 38px;";
      }
    },
    // 清空输入输入框，清空整行数据
    clearCode() {
      if (this.row.PART_NO) {
        let results = this.row;
        for (let key in results) {
          results[key] = "";
        }
        var parent = this.$utils.getHasFormFieldParentComponent(this);
        parent.formField.PART_NO = "";
        parent.formField.PART_NAME = "";
        // for (let key in parent.formField) {
        //   if (results.hasOwnProperty(key)) {
        //     parent.formField[key] = results[key];
        //   }
        // }
      }
    }
  }
};
</script>
